<?php
class buyAction extends security_normal {
	
	function action(){
		$miceSession = new session();	
		if($miceSession->get('mu__userid')<1)
		{
			$uid=0;
			$name='';
		}
		else
		{
			$uid=$miceSession->get('mu__userid');
			$name=$miceSession->get('mu__loginname');
		}
		$pid=ceil($this->_getParamId(1));
		$article=new model_Article();
		$article->setSubsection('WHERE isvisible=0 AND type=\'article1\' AND article_id='.$pid);
		$ArticleRS=$article->doSelectOne();
		if(!$ArticleRS){
			MessageBox('错误信息',MICE_URL,'对不起,您查看的产品信息不存在或已经被删除');
			exit;
		}

		global $conn;
		if($_POST){
			if($_POST['checkcode']<>$miceSession->get('checkcode')){
				MessageBox('验证码错误','back');
				exit;
			}

			if($_POST['name']==''){
				MessageBox('请填写姓名','back');
				exit;
			}

			if($_POST['content']<1){
				MessageBox('请填写购买数量','back');
				exit;
			}

			$form=new model_Form();
			$form->setName(MiceFilterHtml($_POST['name']));
			$form->setUserId($uid);
			$form->setEmail(MiceFilterHtml($_POST['email']));
			$form->setTitle(MiceFilterHtml($_POST['title']));
			$form->setCreatedat(time());
			$form->setType('product');
			$form->setIp(GetRealIp());
			$form->setContent(MiceFilterHtml($_POST['content']));
			$results=$form->doInsert();

			if($results)
				$exeresult='提交成功';
			else
				$exeresult='提交失败';
			MessageBox($exeresult,MICE_URL,'我们的工作人员会尽快按照您提供的联系方式和您联系');
			exit;
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("pid",$pid);
		$smarty->assign("title",$ArticleRS->getTitle());
		$smarty->assign("checkcode",MICE_URL.'code.php');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>